//
//  SN_Question_TableViewCell.m
//  Shiyun_Newspaper
//
//  Created by zz on 17/6/14.
//  Copyright © 2017年 ShiYun. All rights reserved.
//

#import "SN_Question_TableViewCell.h"

@implementation SN_Question_TableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        _leftView = [[UIView alloc] initWithFrame:CGRectMake(15, 9, 4, 16)];
        _leftView.backgroundColor = [UIColor colorWithHexString:@"#fb524a"];
        [self.contentView addSubview:_leftView];
        
        _issueBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _issueBtn.layer.cornerRadius = 4;
        _issueBtn.layer.borderWidth = 0.5;
        _issueBtn.layer.borderColor  = [UIColor colorWithHexString:@"#bebebe"].CGColor;
        [_issueBtn setTitle:@"10期" forState:UIControlStateNormal];
        [_issueBtn setBackgroundColor:[UIColor clearColor]];
        [_issueBtn setTitleColor:[UIColor colorWithHexString:@"#3b3b3b"] forState:UIControlStateNormal];
        [_issueBtn setTitleColor:[UIColor colorWithHexString:@"#afafaf"] forState:UIControlStateSelected];
        _issueBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        _issueBtn.frame = CGRectMake(CGRectGetMaxX(_leftView.frame) + 8, 5, 48, 24);
        [self.contentView addSubview:_issueBtn];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_issueBtn.frame) + 10, 9.5, 300, 15)];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        _titleLabel.textColor = [UIColor colorWithHexString:@"#3b3b3b"];
        _titleLabel.text = @"第十期 十以内的加减乘除法";
        [self.contentView addSubview:_titleLabel];
    }
    
    return self;
}

- (void)setModel:(SN_NewspaperModel *)model {
    
    NSString *editionType = [NSString stringWithFormat:@"%ld期",(long)model.phase];
    
    [_issueBtn setTitle:editionType forState:UIControlStateNormal];
    _titleLabel.text = model.newsname;
    
    if (model.isread) {
        
        _titleLabel.textColor = [UIColor colorWithHexString:@"#afafaf"];
        _issueBtn.selected = YES;
    }else {
        _titleLabel.textColor = [UIColor colorWithHexString:@"#3b3b3b"];
        _issueBtn.selected = NO;
    }
    
    if (model.isFirstIndex) {
        
        _leftView.backgroundColor = [UIColor colorWithHexString:@"#fb524a"];
    }else {
        
        _leftView.backgroundColor = [UIColor colorWithHexString:@"#dedede"];
    }
}

@end
